/*
	Editorial by HTML5 UP
	html5up.net | @ajlkn
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
*/

(function($) {

	var	$window = $(window),
		$head = $('head'),
		$body = $('body');

	// Breakpoints.
		breakpoints({
			xlarge:   [ '1281px',  '1680px' ],
			large:    [ '981px',   '1280px' ],
			medium:   [ '737px',   '980px'  ],
			small:    [ '481px',   '736px'  ],
			xsmall:   [ '361px',   '480px'  ],
			xxsmall:  [ null,      '360px'  ],
			'xlarge-to-max':    '(min-width: 1681px)',
			'small-to-xlarge':  '(min-width: 481px) and (max-width: 1680px)'
		});

	// Stops animations/transitions until the page has ...

		// ... loaded.
			$window.on('load', function() {
				window.setTimeout(function() {
					$body.removeClass('is-preload');
				}, 100);
			});

		// ... stopped resizing.
			var resizeTimeout;

			$window.on('resize', function() {

				// Mark as resizing.
					$body.addClass('is-resizing');

				// Unmark after delay.
					clearTimeout(resizeTimeout);

					resizeTimeout = setTimeout(function() {
						$body.removeClass('is-resizing');
					}, 100);

			});

	// Fixes.

		// Object fit images.
			if (!browser.canUse('object-fit')
			||	browser.name == 'safari')
				$('.image.object').each(function() {

					var $this = $(this),
						$img = $this.children('img');

					// Hide original image.
						$img.css('opacity', '0');

					// Set background.
						$this
							.css('background-image', 'url("' + $img.attr('src') + '")')
							.css('background-size', $img.css('object-fit') ? $img.css('object-fit') : 'cover')
							.css('background-position', $img.css('object-position') ? $img.css('object-position') : 'center');

				});

	// Sidebar.
		var $sidebar = $('#sidebar'),
			$sidebar_inner = $sidebar.children('.inner');

		// Inactive by default on <= large.
			breakpoints.on('<=large', function() {
				$sidebar.addClass('inactive');
			});

			breakpoints.on('>large', function() {
				$sidebar.removeClass('inactive');
			});

		// Hack: Workaround for Chrome/Android scrollbar position bug.
			if (browser.os == 'android'
			&&	browser.name == 'chrome')
				$('<style>#sidebar .inner::-webkit-scrollbar { display: none; }</style>')
					.appendTo($head);

		// Toggle.
			$('<a href="#sidebar" class="toggle">Toggle</a>')
				.appendTo($sidebar)
				.on('click', function(event) {

					// Prevent default.
						event.preventDefault();
						event.stopPropagation();

					// Toggle.
						$sidebar.toggleClass('inactive');

				});

		// Events.

			// Link clicks.
				$sidebar.on('click', 'a', function(event) {

					// >large? Bail.
						if (breakpoints.active('>large'))
							return;

					// Vars.
						var $a = $(this),
							href = $a.attr('href'),
							target = $a.attr('target');

					// Prevent default.
						event.preventDefault();
						event.stopPropagation();

					// Check URL.
						if (!href || href == '#' || href == '')
							return;

					// Hide sidebar.
						$sidebar.addClass('inactive');

					// Redirect to href.
						setTimeout(function() {

							if (target == '_blank')
								window.open(href);
							else
								window.location.href = href;

						}, 500);

				});

			// Prevent certain events inside the panel from bubbling.
				$sidebar.on('click touchend touchstart touchmove', function(event) {

					// >large? Bail.
						if (breakpoints.active('>large'))
							return;

					// Prevent propagation.
						event.stopPropagation();

				});

			// Hide panel on body click/tap.
				$body.on('click touchend', function(event) {

					// >large? Bail.
						if (breakpoints.active('>large'))
							return;

					// Deactivate.
						$sidebar.addClass('inactive');

				});

		// Scroll lock.
		// Note: If you do anything to change the height of the sidebar's content, be sure to
		// trigger 'resize.sidebar-lock' on $window so stuff doesn't get out of sync.

			$window.on('load.sidebar-lock', function() {

				var sh, wh, st;

				// Reset scroll position to 0 if it's 1.
					if ($window.scrollTop() == 1)
						$window.scrollTop(0);

				$window
					.on('scroll.sidebar-lock', function() {

						var x, y;

						// <=large? Bail.
							if (breakpoints.active('<=large')) {

								$sidebar_inner
									.data('locked', 0)
									.css('position', '')
									.css('top', '');

								return;

							}

						// Calculate positions.
							x = Math.max(sh - wh, 0);
							y = Math.max(0, $window.scrollTop() - x);

						// Lock/unlock.
							if ($sidebar_inner.data('locked') == 1) {

								if (y <= 0)
									$sidebar_inner
										.data('locked', 0)
										.css('position', '')
										.css('top', '');
								else
									$sidebar_inner
										.css('top', -1 * x);

							}
							else {

								if (y > 0)
									$sidebar_inner
										.data('locked', 1)
										.css('position', 'fixed')
										.css('top', -1 * x);

							}

					})
					.on('resize.sidebar-lock', function() {

						// Calculate heights.
							wh = $window.height();
							sh = $sidebar_inner.outerHeight() + 30;

						// Trigger scroll.
							$window.trigger('scroll.sidebar-lock');

					})
					.trigger('resize.sidebar-lock');

				});

	// Menu.
		var $menu = $('#menu'),
			$menu_openers = $menu.children('ul').find('.opener');

		// Openers.
			$menu_openers.each(function() {

				var $this = $(this);

				$this.on('click', function(event) {

					// Prevent default.
						event.preventDefault();

					// Toggle.
						$menu_openers.not($this).removeClass('active');
						$this.toggleClass('active');

					// Trigger resize (sidebar lock).
						$window.triggerHandler('resize.sidebar-lock');

				});

			});

})(jQuery);
var kuId = [0, 0, 0, 0, 0, 0];
function addToTheList(kuid, gongzi, mingchengid){
	xuanze(kuid, gongzi, mingchengid);
	var firstPrice = document.getElementById("yiqian").innerHTML;
	var secondPrice = document.getElementById("erqian").innerHTML;
	var thirdPrice = document.getElementById("sanqian").innerHTML;
	var fourthPrice = document.getElementById("siqian").innerHTML;
	var fifthPrice = document.getElementById("wuqian").innerHTML;
	var sum = parseInt(firstPrice) + parseInt(secondPrice) +
		parseInt(thirdPrice) + parseInt(fourthPrice) + parseInt(fifthPrice);
	document.getElementById("zongji").innerHTML = sum;
}
function deleteFromTheList(pos){
	if(pos === 1){
		document.getElementById("yihaowei").innerHTML = "";
		document.getElementById("yiqian").innerHTML = "0";
		kuId[1] = 0;
	}
	if(pos === 2){
		document.getElementById("erhaowei").innerHTML = "";
		document.getElementById("erqian").innerHTML = "0";
		kuId[2] = 0;
	}
	if(pos === 3){
		document.getElementById("sanhaowei").innerHTML = "";
		document.getElementById("sanqian").innerHTML = "0";
		kuId[3] = 0;
	}
	if(pos === 4){
		document.getElementById("sihaowei").innerHTML = "";
		document.getElementById("siqian").innerHTML = "0";
		kuId[4] = 0;
	}
	if(pos === 5){
		document.getElementById("wuhaowei").innerHTML = "";
		document.getElementById("wuqian").innerHTML = "0";
		kuId[5] = 0;
	}
	var firstPrice = document.getElementById("yiqian").innerHTML;
	var secondPrice = document.getElementById("erqian").innerHTML;
	var thirdPrice = document.getElementById("sanqian").innerHTML;
	var fourthPrice = document.getElementById("siqian").innerHTML;
	var fifthPrice = document.getElementById("wuqian").innerHTML;
	var sum = parseInt(firstPrice) + parseInt(secondPrice) +
		parseInt(thirdPrice) + parseInt(fourthPrice) + parseInt(fifthPrice);
	document.getElementById("zongji").innerHTML = sum;
}
function xuanze(kuid, gongzi, mingchengid){
	var firstName = document.getElementById("yihaowei").innerHTML;
	var secondName = document.getElementById("erhaowei").innerHTML;
	var thirdName = document.getElementById("sanhaowei").innerHTML;
	var fourthName = document.getElementById("sihaowei").innerHTML;
	var fifthName = document.getElementById("wuhaowei").innerHTML;
	var firstPrice = document.getElementById("yiqian").innerHTML;
	var secondPrice = document.getElementById("erqian").innerHTML;
	var thirdPrice = document.getElementById("sanqian").innerHTML;
	var fourthPrice = document.getElementById("siqian").innerHTML;
	var fifthPrice = document.getElementById("wuqian").innerHTML;
	var qiuyuanshu = 0;
	for(i = 1; i < 6; i++){
		if(kuId[i] !== 0){
			qiuyuanshu++;
		}
	}
	if(qiuyuanshu === 5){
		alert("阵容已满，请先删除球员再替换球员！");
		return;
	}
	if(kuid === 1){
		if(kuId[1] === 0){
			// 0 +1 -> 1
			kuId[1] = 1;
			document.getElementById("yihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
			document.getElementById("yiqian").innerHTML = gongzi;
			firstPrice = gongzi;
			return;
		}
		if(kuId[1] === 1){
			if(kuId[2] === 0){
				// 1 0 +1 -> 1 1
				kuId[2] = 1;
				document.getElementById("erqian").innerHTML = gongzi;
				document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
				return;
			}
			if(kuId[2] === 1){
				// 1 1 +1
				alert("PG和SG位置已经被两个库一球员占用，无法再在阵容中添加库一球员，请先删除球员再替换球员！");
				return;
			}
			if(kuId[2] === 2){
				if(kuId[3] === 0){
					// 1 2 0 +1 -> 1 1 2
					kuId[3] = 2;
					kuId[2] = 1;
					document.getElementById("sanhaowei").innerHTML = secondName;
					document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("erqian").innerHTML = gongzi;
					document.getElementById("sanqian").innerHTML = secondPrice;
					return;
				}
				if(kuId[3] === 2){
					// 1 2 2 +1
					alert("PG、SG和SF位置已经被三个球员占用，无法再在阵容中添加库一球员，请先删除球员再替换球员！");
					return;
				}
				if(kuId[3] === 3){
					if(kuId[4] === 4){
						//1 2 3 4 0 +1 ->1 1 2 3 4
						kuId[5] = 4;
						kuId[4] = 3;
						kuId[3] = 2;
						kuId[2] = 1;
						document.getElementById("wuhaowei").innerHTML = fourthName;
						document.getElementById("wuqian").innerHTML = fourthPrice;
						document.getElementById("sihaowei").innerHTML = thirdName;
						document.getElementById("siqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = secondName;
						document.getElementById("sanqian").innerHTML = secondPrice;
						document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("erqian").innerHTML = gongzi;
						return;
					}
					if(kuId[4] === 3){
						// 1 2 3 3
						alert("PF位置的球员为3号库球员，无法放在C位置，无法再在阵容中添加库一球员，请先删除球员再替换球员！");
						return;
					}
					if(kuId[4] === 0){
						//1 2 3 0 ? -> 1 1 2 3 ?
						kuId[4] = 3;
						kuId[3] = 2;
						kuId[2] = 1;
						document.getElementById("sihaowei").innerHTML = thirdName;
						document.getElementById("siqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = secondName;
						document.getElementById("sanqian").innerHTML = secondPrice;
						document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("erqian").innerHTML = gongzi;
						return;
					}
				}
			}
		}
	}
	if(kuid === 2){
		if(kuId[2] === 0){
			// ? 0 -> ? 2
			kuId[2] = 2;
			document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
			document.getElementById("erqian").innerHTML = gongzi;
			return;
		}
		if(kuId[2] !== 0){
			if(kuId[3] === 0){
				// ? 1/2 0 ? ? -> ? 1/2 2 ? ?
				kuId[3] = 2;
				document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
				document.getElementById("sanqian").innerHTML = gongzi;
				return;
			}
			if(kuId[3] === 2){
				if(kuId[2] === 1){
					if(kuId[1] === 0){
						kuId[1] = 1;
						kuId[2] = 2;
						document.getElementById("yihaowei").innerHTML = secondName;
						document.getElementById("yiqian").innerHTML = secondPrice;
						document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("erqian").innerHTML = gongzi;
						return;
					}
					if(kuId[1] === 1){
						alert("PG、SG和SF位置被占用，无法再在阵容中添加库二球员，请先删除球员再替换球员！");
						return;
					}
				}
				alert("SF位置的球员为2号库球员，无法放在PF位置，无法再在阵容中添加库二球员，请先删除球员再替换球员！");
				return;
			}
			if(kuId[3] === 3){
				if(kuId[4] === 0){
					// ? 1/2 3 0 ? -> ? 1/2 2 3 ?
					kuId[4] = 3;
					kuId[3] = 2;
					document.getElementById("sihaowei").innerHTML = thirdName;
					document.getElementById("siqian").innerHTML = thirdPrice;
					document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("sanqian").innerHTML = gongzi;
					return;
 				}
				if(kuId[4] === 3){
					// ? 1/2 3 3 ?
					alert("PF位置的球员为3号库球员，无法放在C位置，无法再在阵容中添加库二球员，请先删除球员再替换球员！");
					return;
				}
				if(kuId[4] === 4){
					if(kuId[5] === 0){
						// 0 1/2 3 4 0 -> 0 1/2 2 3 4
						kuId[5] = 4;
						kuId[4] = 3;
						kuId[3] = 2;
						document.getElementById("wuhaowei").innerHTML = fourthName;
						document.getElementById("wuqian").innerHTML = fourthPrice;
						document.getElementById("sihaowei").innerHTML = thirdName;
						document.getElementById("siqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("sanqian").innerHTML = gongzi;
						return;
					}
					if(kuId[5] === 4){
						// 0 1/2 3 4 4
						if(kuId[2] === 1){
							// 0 1 3 4 4 -> 1 2 3 4 4
							kuId[2] = 2;
							kuId[1] = 1;
							document.getElementById("yihaowei").innerHTML = secondName;
							document.getElementById("yiqian").innerHTML = secondPrice;
							document.getElementById("erhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
							document.getElementById("erqian").innerHTML = gongzi;
							return;
						}
						if(kuId[2] === 2){
							// 0 2 3 4 4
							alert("SG和SF位置均被占用，无法再在阵容中添加库二球员，请先删除球员再替换球员！");
							return;
						}
					}
				}
			}
		}
	}
	if(kuid === 3){
		if(kuId[3] === 0){
			// ? ? 0 ? ? -> ? ? 3 ? ?
			kuId[3] = 3;
			document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
			document.getElementById("sanqian").innerHTML = gongzi;
			return;
		}
		if(kuId[3] === 2){
			// ? ? 2 ? ?
			if(kuId[4] === 0){
				// ? ? 2 0 ? -> ? ? 2 3 ?
				kuId[4] = 3;
				document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
				document.getElementById("siqian").innerHTML = gongzi;
				return;
			}
			if(kuId[4] === 3){
				if(kuId[2] === 0){
					// ? 0 2 3 ? -> ? 2 3 3 ?
					kuId[2] = 2;
					kuId[3] = 3;
					document.getElementById("erhaowei").innerHTML = thirdName;
					document.getElementById("erqian").innerHTML = thirdPrice;
					document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("sanqian").innerHTML = gongzi;
					return;
				}
				if(kuId[2] === 1){
					if(kuId[1] === 0){
						//0 1 2 3 ? -> 1 2 3 3 ?
						kuId[1] = 1;
						kuId[2] = 2;
						kuId[3] = 3;
						document.getElementById("yihaowei").innerHTML = secondName;
						document.getElementById("yiqian").innerHTML = secondPrice;
						document.getElementById("erhaowei").innerHTML = thirdName;
						document.getElementById("erqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("sanqian").innerHTML = gongzi;
						return;
					}
					if(kuId[1] === 1){
						//1 1 2 3 ?
						alert("PG、SG、SF和PF位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
						return;
					}
				}
				if(kuId[2] === 2){
					//? 2 2 3
					alert("SG、SF和PF位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
					return;
				}
			}
			if(kuId[4] === 4){
				if(kuId[5] === 0){
					//? ? 2 4 0 -> ? ? 2 3 4
					kuId[4] = 3;
					kuId[5] = 4;
					document.getElementById("wuhaowei").innerHTML = fourthName;
					document.getElementById("wuqian").innerHTML = fourthPrice;
					document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("siqian").innerHTML = gongzi;
					return;
				}
				if(kuId[5] === 4){
					if(kuId[2] === 0){
						kuId[2] = 2;
						kuId[3] = 3;
						document.getElementById("erhaowei").innerHTML = thirdName;
						document.getElementById("erqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("sanqian").innerHTML = gongzi;
						return;
					}
					if(kuId[2] === 1){
						if(kuId[1] === 0){
							kuId[1] = 1;
							kuId[2] = 2;
							kuId[3] = 3;
							document.getElementById("yihaowei").innerHTML = secondName;
							document.getElementById("yiqian").innerHTML = secondPrice;
							document.getElementById("erhaowei").innerHTML = thirdName;
							document.getElementById("erqian").innerHTML = thirdPrice;
							document.getElementById("sanhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
							document.getElementById("sanqian").innerHTML = gongzi;
							return;
						}
						if(kuId[1] === 1){
							alert("所有位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
							return;
						}
					}
					if(kuId[2] === 2){
						alert("除PG外所有位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
						return;
					}
				}
			}
		}
		if(kuId[3] === 3){
			if(kuId[4] === 0){
				// ? ? 3 0 ? -> ? ? 3 3 ?
				kuId[4] = 3;
				document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
				document.getElementById("siqian").innerHTML = gongzi;
				return;
			}
			if(kuId[4] === 3){
				alert("PF和SF位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
				return;
			}
			if(kuId[4] === 4){
				if(kuId[5] === 0){
					//? ? 3 4 0 -> ? ? 3 3 4
					kuId[4] = 3;
					kuId[5] = 4;
					document.getElementById("wuhaowei").innerHTML = fourthName;
					document.getElementById("wuqian").innerHTML = fourthPrice;
					document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("siqian").innerHTML = gongzi;
					return;
				}
				if(kuId[5] === 4){
					//? ? 2 4 4
					alert("SF、PF和C位置均被占用，无法再在阵容中添加库三球员，请先删除球员再替换球员！");
					return;
				}
			}
		}
	}
	if(kuid === 4){
		if(kuId[5] === 0){
			//? ? ? ? 0 -> ? ? ? ? 4
			kuId[5] = 4;
			document.getElementById("wuhaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
			document.getElementById("wuqian").innerHTML = gongzi;
			return;
		}
		if(kuId[5] === 4){
			if(kuId[4] === 0){
				//? ? ? 0 4 -> ? ? ? 4 4
				kuId[4] = 4;
				document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
				document.getElementById("siqian").innerHTML = gongzi;
				return;
			}
			if(kuId[4] === 4){
				//? ? ? 4 4
				alert("PF和C位置均被占用，无法再在阵容中添加库四球员，请先删除球员再替换球员！");
				return;
			}
			if(kuId[4] === 3){
				if(kuId[3] === 0){
					//? ? 0 3 4 -> ? ? 3 4 4
					kuId[3] = 3;
					kuId[4] = 4;
					document.getElementById("sanhaowei").innerHTML = fourthName;
					document.getElementById("sanqian").innerHTML = fourthPrice;
					document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
					document.getElementById("siqian").innerHTML = gongzi;
					return;
				}
				if(kuId[3] === 2){
					if(kuId[2] === 1){
						if(kuId[1] === 0){
							// 0 1 2 3 4 -> 1 2 3 4 4
							kuId[1] = 1;
							kuId[2] = 2;
							kuId[3] = 3;
							kuId[4] = 4;
							document.getElementById("yihaowei").innerHTML = secondName;
							document.getElementById("yiqian").innerHTML = secondPrice;
							document.getElementById("erhaowei").innerHTML = thirdName;
							document.getElementById("erqian").innerHTML = thirdPrice;
							document.getElementById("sanhaowei").innerHTML = fourthName;
							document.getElementById("sanqian").innerHTML = fourthPrice;
							document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
							document.getElementById("siqian").innerHTML = gongzi;
							return;
						}
						if(kuId[1] === 1){
							alert("所有位置均被占用，无法再在阵容中添加库四球员，请先删除球员再替换球员！");
							return;
						}
					}
					if(kuId[2] === 0){
						//? 0 2 3 4 -> ? 2 3 4 4
						kuId[2] = 2;
						kuId[3] = 3;
						kuId[4] = 4;
						document.getElementById("erhaowei").innerHTML = thirdName;
						document.getElementById("erqian").innerHTML = thirdPrice;
						document.getElementById("sanhaowei").innerHTML = fourthName;
						document.getElementById("sanqian").innerHTML = fourthPrice;
						document.getElementById("sihaowei").innerHTML = document.getElementById(mingchengid).innerHTML;
						document.getElementById("siqian").innerHTML = gongzi;
						return;
					}
				}
				if(kuId[3] === 3){
					alert("SF、PF和C位置均被占用，无法再在阵容中添加库四球员，请先删除球员再替换球员！");
					return;
				}
			}
		}
	}
	/*
	1 1 2 3 4
	1 1 2 4 4
	1 1 3 3 4
	1 1 3 4 4
	1 2 2 3 4
	1 2 2 4 4
	1 2 3 3 4
	1 2 3 4 4
	*/
}

